;(function () {
  new Vue({
    el: '#cEnd',
    data: {
      flag: true,
      beginTime: '',
      endTime: '',
      orders: '#',
      columns: '#',
      pagetotal: 0,
      page: 1,
      limit: ['10'],
      pageCounts: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
      modulesList: [],
      typelist: [],
      typeStatus: [],
      keyword: '',
      publishingType: '#',
      moduleId: [],
      data: [],
      erweimaflag: false,
      quanxian: JSON.parse(window.localStorage.getItem('permissions')),
			isValidateLt: [{name: '是', code: 'Y'}, {name: '否', code: 'N'}],
			isValidate: []
    },
    filters: {
      framtTime (time) {
        return hlDateUtil.formatDate(time,'yyyy-MM-dd HH:mm:ss')
      },
      formatDate: function(time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatUTCDate(time,'yyyy-MM-dd')
      },
    },
    methods: {
			//新加的
			isValidateSel (arr) {
				this.isValidate = [arr[0].code]
			},

      //显示隐藏查询条件
      showHideTerm () {
        this.flag = !this.flag;
      },
      // 设置背景色
      addbgcolor (index) {
        let el = document.querySelectorAll('.house-two-tone');
        let el0 = document.querySelectorAll('.house-operate')
        el[index].classList.add('house-two-tone-hover')
        el0[index].classList.add('house-two-tone-hover')
      },
      //删除背景色
      removebgcolor (index) {
        let el = document.querySelectorAll('.house-two-tone');
        let el0 = document.querySelectorAll('.house-operate')
        el[index].classList.remove('house-two-tone-hover')
        el0[index].classList.remove('house-two-tone-hover')
      },
      //最后更新时间
      updateTime () {
        setTimeout(() => {
          this.getListData();
        }, 300)
        if (this.columns != 'UT') {
          this.columns = 'UT';
          this.orders = 'ASC';
          return
        }
        if (this.orders == 'ASC') {
          this.orders = 'DESC'
          return
        }
        if (this.orders == 'DESC') {
          this.orders = 'ASC'
          return
        }
      },
      //创建时间
      createTime () {
        setTimeout(() => {
          this.getListData();
        }, 300)
        if (this.columns != 'CT') {
          this.columns = 'CT';
          this.orders = 'ASC';
          return
        }
        if (this.orders == 'ASC') {
          this.orders = 'DESC'
          return
        }
        if (this.orders == 'DESC') {
          this.orders = 'ASC'
          return
        }
      },
      //新建信息
      createInfo () {
        hlUrlUtil.goTo('createInfo98k',{ddtab: true},true)
      },
      //编辑信息
      editorPerview (id, type) {
        let typec = type == '多篇' ? 'true' : 'false';
        hlUrlUtil.goTo('editInfo98k',{ddtab: true, portalArticleId: id, type: typec, clear: true},true)
      },
      //模块列表获取
      getmodules () {
        hlhttp.get({
          url: 'portal/modules',
          success: (data) => {
            this.modulesList = hlArrayUtil.replaceData(data, [{key: 'moduleName', rKey: 'name'}, {key: 'moduleId', rKey: 'code'}]);
          }
        })
      },
      //获取模块id
      eventModule (arr) {
        this.moduleId = [arr[0].code];
      },
      //获取状态
      gettypelist () {
        hlhttp.get({
          url: 'configure/dict',
          data: {module_code: 'MNHU', config_name: 'MNHU_ELEMENT_ARTICLE_TYPE'},
          success: (data) => {
            this.typelist = hlArrayUtil.replaceData(data, [{key: 'dictName', rKey: 'name'}, {key: 'dictCode', rKey: 'code'}]);
          }
        })
      },
      eventType (arr) {
        this.typeStatus = [arr[0].code];
      },
      //展示数量
      eventPage (arr) {
        this.limit = [arr[0].code];
        this.getListData()
      },
      //重置
      reset () {
        this.keyword = '';
        this.beginTime = '';
        this.endTime = '';
        this.moduleId = [];
        this.typeStatus = [];
        this.orders = '#';
        this.columns = '#';
				this.isValidate = [];
        this.page = 1;
        this.limit = ['10'];
        this.getListData()
      },
      getListData0 () {
        this.page = 1;
        this.limit = ['10'];
        this.getListData()
      },
      //获取列表
      getListData () {
        hlhttp.get({
          url: 'user/publishings',
          data: {
            "keyword": this.keyword || '#',
            "begin_date": this.beginTime || '#',
            "end_date": this.endTime || '#',
            "module_id": this.moduleId.length ? this.moduleId[0] : '#',
            "publishing_type": this.typeStatus.length ? this.typeStatus[0] : '#',
            "orders": this.orders,
						"is_partake": this.isValidate.length ? this.isValidate[0] : '#',
            "columns": this.columns,
            "page": this.page,
            "limit": this.limit[0]
          },
          success: (data) => {
            this.data = data;
            $("#page").initPage(data.totalPage, this.page, (n) => {
              if (this.page == n) {
                return
              }
              this.page = n;
              this.getListData();
            });
          }
        })
      },
      //预览
      previewDetail (id) {
        hlUrlUtil.goTo('previewInfo98k',{ddtab: true, portalArticleId: id, clear: true},true)
      },
      //删除某条信息
      delOne (id) {
        hllayer.confirm1('此操作不可逆，确认删除吗？', () => {
          hlhttp.delete({
            url: 'user/publishing?portal_article_id='+id,
            success: (data) => {
              hl.toast('删除成功')
              this.getListData();
            }
          })
        })
      },
      //启用停用
      putStatus (id, status, type) {
        let isStatus = status == 'Y' ? 'N' : 'Y';
        if (status == 'Y') {
          hlhttp.put({
            url: 'user/set_enable_publishing',
            data: {portal_article_id: id, is_valid: isStatus},
            success: (data) => {
              hl.toast('操作成功')
              this.getListData();
            }
          })
          return
        }
        if (type == '单篇') {
          hllayer.confirm1('启用单篇类型文章时将停用上一篇已启用文章！', () => {
            hlhttp.put({
              url: 'user/set_enable_publishing',
              data: {portal_article_id: id, is_valid: isStatus},
              success: (data) => {
                hl.toast('操作成功')
                this.getListData();
              }
            })
          })
        } else {
          hlhttp.put({
            url: 'user/set_enable_publishing',
            data: {portal_article_id: id, is_valid: isStatus},
            success: (data) => {
              hl.toast('操作成功')
              this.getListData();
            }
          })
        }
      },
			copyURL (item) {
				let functionCate;
				if (item.publishingType == 'ATCLS') {
					functionCate = 'COPYURL_ATCLS'
				}
				if (item.publishingType == 'ATCLM') {
					functionCate = 'COPYURL_ATCLM'
				}
				hlhttp.get({
					url: 'configure/copy_url',
					data: {
						function_cate: functionCate,
						params: item.portalArticleId
					},
					async:false,
					success: (data) => {
						var Url = document.getElementById("copyInput");
						Url.value = data.copyUrl;
					}
				})

			},
			copyss () {
				var Url = document.getElementById("copyInput");
				Url.select(); // 选择对象
				document.execCommand("Copy"); // 执行浏览器复制命令
				hl.toast('复制成功')
			}
    },
    created () {
      hlSelectUi()
    },
    mounted () {
      this.getmodules()
      this.gettypelist()
      this.getListData()
    }
  })
} ())
